/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __MP3FILE_H__
#define __MP3FILE_H__

#include "FormatMP3/MP3Header.h"
#include "FormatMP3/Filter.h"
#include "FormatMP3/BitStream.h"
#include "FormatMP3/MP3Decoder.h"
#include "FormatMP3/OutputBuffer.h"

#include <SharedRep.h>
#include "DataSource.h"
#include <filesystem/String.hpp>
#include <vector>
#include <logs/Log.h>

#include "xm/Format.h"

namespace liba
{

namespace noise
{

class MP3File : public DataSource
{
	CMP3Header m_header;
	CBitStream m_stream;
	CSynthesisFilter * m_filter1, * m_filter2;
	CMP3Decoder * m_decoder;
	COutputBuffer * m_output;

	bool error;
	bool to_stop;

	Format format;

	int samples_decoded;
	std::vector<char> decoded_data;

public:
	explicit MP3File( const filesystem::String & file_name );
	virtual ~MP3File();

	virtual int get_frequency();
	virtual bool has_native(Type channel);
	virtual int get_length();
	virtual int decode(int samples);
	virtual void get_data(Type channel, void * dst, int dst_stride, int dst_bits);

	bool is_valid()const
	{
		return !error;
	}
};

} // namespace noise
} // namespace liba
using namespace liba;

#endif //__MP3FILE_H__